package com.shbaiche.bifenba.adapter.match;

import android.app.Activity;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.match.MatchesVo;
import com.shbaiche.bifenba.model.match.OddsInfoVo;
import com.shbaiche.bifenba.model.match.OddsInfoVoBox;
import com.shbaiche.bifenba.model.match.TeamHistoryVo;

import butterknife.BindView;
import cn.droidlover.xdroid.base.SimpleRecAdapter;
import cn.droidlover.xdroid.kit.KnifeKit;

/**
 * 比赛赔率列表
 */

public class MatchOddsInfoListAdapter extends SimpleRecAdapter<OddsInfoVoBox, MatchOddsInfoListAdapter.ViewHolder> {
    private Activity context;
    private int color_blue;

    public MatchOddsInfoListAdapter(Activity context) {
        super(context);
        this.context = context;
        color_blue = Color.parseColor("#FBFEFF");
    }

    @Override
    public ViewHolder newViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_match_odds_info_list;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        OddsInfoVoBox item = data.get(position);

        holder.tvName.setText(item.getCompanyName());
        holder.tvTime.setText(item.getDate());

        StringBuffer sbType = new StringBuffer();
        StringBuffer sbOddsA = new StringBuffer();
        StringBuffer sbOddsB = new StringBuffer();
        StringBuffer sbOddsC = new StringBuffer();

        if(item.getVoList()!=null && item.getVoList().size()>0){

            for (int i=0;i<item.getVoList().size();i++){
                if(i==0){
                    sbType.append("<font color=\"red\">"+item.getVoList().get(i).getType()+"</font>");

                }else{
                    sbType.append(item.getVoList().get(i).getType());
                }

                sbOddsA.append(item.getVoList().get(i).getFirst());
                sbOddsB.append(item.getVoList().get(i).getSecond());
                sbOddsC.append(item.getVoList().get(i).getThird());
                if(i!=item.getVoList().size()-1){
                    sbType.append("<br/>");
                    sbOddsA.append("\n");
                    sbOddsB.append("\n");
                    sbOddsC.append("\n");
                }
            }
        }
        holder.tvType.setText(Html.fromHtml(sbType.toString()));
        holder.tvOddsA.setText(sbOddsA.toString());
        holder.tvOddsB.setText(sbOddsB.toString());
        holder.tvOddsC.setText(sbOddsC.toString());

        if(position % 2 == 0){
            holder.itemView.setBackgroundColor(Color.WHITE);
        }else{
            holder.itemView.setBackgroundColor(color_blue);
        }


        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getRecItemClick() != null) {

                }
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {



        @BindView(R.id.tv_name)
        TextView tvName;

        @BindView(R.id.tv_type)
        TextView tvType;

        @BindView(R.id.tv_odds_a)
        TextView tvOddsA;

        @BindView(R.id.tv_odds_b)
        TextView tvOddsB;

        @BindView(R.id.tv_odds_c)
        TextView tvOddsC;

        @BindView(R.id.tv_time)
        TextView tvTime;




        public ViewHolder(View itemView) {
            super(itemView);
            KnifeKit.bind(this, itemView);
        }
    }
}
